# Copyright (C) 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//tools/build:rules.bzl", "api_template")

package(default_visibility = ["//visibility:public"])

filegroup(
    name = "templates",
    srcs = glob(["**/*.tmpl"]),
)

filegroup(
    name = "go_common_deps",
    srcs = [
        "common.tmpl",
        "go_common.tmpl",
    ],
)

filegroup(
    name = "go_convert_common_deps",
    srcs = [
        "go_convert_common.tmpl",
        ":go_common_deps",
    ],
)

filegroup(
    name = "cpp_common_deps",
    srcs = [
        "common.tmpl",
        "cpp_common.tmpl",
    ],
)

filegroup(
    name = "gfxapi_common_deps",
    srcs = [
        "gfx_api_common.tmpl",
        ":cpp_common_deps",
    ],
)

api_template(
    name = "api",
    includes = [":go_common_deps"],
    outputs = [
        "api.go",
        "api_amrp.go",
        "api_builder.go",
        "api_classes.go",
        "api_commands.go",
        "api_constants.go",
        "api_enums.go",
        "api_pointers.go",
        "api_slices.go",
        "api_state.go",
    ],
    template = "api.go.tmpl",
)

api_template(
    name = "api_types",
    includes = [":go_common_deps"],
    outputs = ["api_types.go"],
    template = "api_types.go.tmpl",
)

api_template(
    name = "mutate",
    includes = [":go_common_deps"],
    outputs = ["mutate.go"],
    template = "mutate.go.tmpl",
)

api_template(
    name = "state_serialize",
    includes = [
        ":go_common_deps",
        ":go_convert_common_deps",
    ],
    outputs = ["state_serialize.go"],
    template = "state_serialize.go.tmpl",
)

api_template(
    name = "constant_sets",
    includes = [":go_common_deps"],
    outputs = ["constant_sets.go"],
    template = "constant_sets.go.tmpl",
)

api_template(
    name = "convert",
    includes = [
        ":go_common_deps",
        ":go_convert_common_deps",
    ],
    outputs = ["convert.go"],
    template = "convert.go.tmpl",
)

api_template(
    name = "proto",
    includes = ["common.tmpl"],
    outputs = ["api.proto"],
    template = "api.proto.tmpl",
)

api_template(
    name = "specific_gfx_api.cpp",
    includes = [":cpp_common_deps"],
    outputs = ["{api}_gfx_api.cpp"],
    template = "specific_gfx_api.cpp.tmpl",
)

api_template(
    name = "specific_gfx_api.h",
    includes = [
        ":cpp_common_deps",
        ":gfxapi_common_deps",
    ],
    outputs = ["{api}_gfx_api.h"],
    template = "specific_gfx_api.h.tmpl",
)

api_template(
    name = "vulkan_gfx_api_extras.cpp",
    includes = [":cpp_common_deps"],
    outputs = ["vulkan_gfx_api_extras.cpp"],
    template = "vulkan_gfx_api_extras.tmpl",
)

api_template(
    name = "api_imports.h",
    includes = [
        "api_classnames.tmpl",
        ":cpp_common_deps",
    ],
    outputs = ["{api}_imports.h"],
    template = "api_imports.h.tmpl",
)

api_template(
    name = "api_spy.h",
    includes = [
        "api_classnames.tmpl",
        ":cpp_common_deps",
    ],
    outputs = ["{api}_spy.h"],
    template = "api_spy.h.tmpl",
)

api_template(
    name = "api_spy.cpp",
    includes = [
        "api_classnames.tmpl",
        ":cpp_common_deps",
    ],
    outputs = [
        "{api}_spy_0.cpp",
        "{api}_spy_1.cpp",
        "{api}_spy_2.cpp",
        "{api}_spy_3.cpp",
        "{api}_spy_subroutines_0.cpp",
        "{api}_spy_subroutines_1.cpp",
    ],
    template = "api_spy.cpp.tmpl",
)

api_template(
    name = "api_types.h",
    includes = [":cpp_common_deps"],
    outputs = ["{api}_types.h"],
    template = "api_types.h.tmpl",
)

api_template(
    name = "api_types.cpp",
    includes = [":cpp_common_deps"],
    outputs = ["{api}_types.cpp"],
    template = "api_types.cpp.tmpl",
)

api_template(
    name = "enum_lookup.go",
    includes = [":go_common_deps"],
    outputs = ["{api}_enum_lookup.go"],
    template = "enum_lookup.go.tmpl",
)
